package com.frame.pageform;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

/**
 * @Title: 系统
 * @Description:
 * @Copyright: Copyright (c) 2012
 * @Company:
 * @author 王海锋
 * @CreatedTime:2012-7-31 下午12:02:31
 * @version 1.0
 */

public class Log4JInit extends HttpServlet{
    private  Logger logger=Logger.getLogger(Log4JInit.class);
    public void init() throws ServletException
    {
        String path=this.getServletContext().getRealPath("/");
        String file=this.getInitParameter("log4j_init_path");
        String logFile=this.getInitParameter("log4j_file_path");
        if(file!=null)
        {
            try{
                Properties prop = new Properties();
                prop.load(new FileInputStream(path+file)); //加载log4j.properties
                prop.setProperty("log4j.appender.logfile.File", path+logFile+ prop.getProperty("log4j.appender.logfile.File")); //设置日志文件的输出路径
                PropertyConfigurator.configure(prop); //加载配置项
            }catch(Exception e){
                logger.info("初始化log4j日志输入路径异常，请检查web.xml参数配置是否正常，异常发生在"+this.getClass().getName()+"类的public void init()方法，异常的愿意是："+e.getMessage(), e.fillInStackTrace());
            }
        }

    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException
    {

    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException
    {

    }

}
